<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "hy_banner".
 *
 * @property int $id
 * @property string $ba_name 导航名称
 * @property string $ba_url_pc 链接地址 pc
 * @property string $ba_url_mini 链接地址 小程序
 * @property int $ba_sort 排序
 * @property string $ca_id 行业分管id
 * @property int $status 状态 1启用,0禁用
 * @property int $type 类型1图片
 * @property string $img_url 图片地址
 * @property string $created_at 创建时间
 * @property string $updated_at 修改时间
 * @property string $deleted_at 删除时间
 */
class Banner extends \yii\db\ActiveRecord
{
    /**
     * 自动更新时间
     */
    public function behaviors()
    {
        return [
            [
                'class' => \yii\behaviors\TimestampBehavior::className(),
                'value' => function () {
                    return date('Y-m-d H:i:s');
                },
            ],
        ];
    }
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'hy_banner';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['ba_name'], 'required'],
            [['img_url'], 'required', 'on' => ['create']],
            [['ba_sort', 'status', 'type'], 'integer'],
            [['created_at', 'updated_at', 'deleted_at'], 'safe'],
            [['img_url'], 'string'],
            [['ba_name', 'ba_url_pc', 'ba_url_mini'], 'string', 'max' => 255],
            [['br_id'], 'string', 'max' => 50],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'ba_name' => '导航名称',
            'ba_url_pc' => 'Pc链接',
            'ba_url_mini' => '小程序链接',
            'ba_sort' => '排序',
            'br_id' => '对应分馆',
            'status' => '状态',
            'type' => '资源分类',
            'img_url' => 'Banner图',
            'created_at' => '添加时间',
            'updated_at' => '修改时间',
            'deleted_at' => '删除时间',
        ];
    }
    /**
     * 场景
     */
    const SCENARIOS_BANNER_CREATE = 'create';
    const SCENARIOS_BANNER_UPDATE = 'update';
    public function scenarios()
    {
        $scenarios = [
            self::SCENARIOS_BANNER_CREATE => ['ba_name', 'ba_url_pc', 'ba_url_mini', 'ba_sort', 'br_id', 'status','img_url'],
            self::SCENARIOS_BANNER_UPDATE => ['ba_name', 'ba_url_pc', 'ba_url_mini', 'ba_sort', 'br_id', 'status','img_url'],
        ];
        return array_merge(parent::scenarios(), $scenarios);
    }
}
